package com.zxc.service.impl;

import com.zxc.dao.AdminDao;
import com.zxc.model.*;
import com.zxc.model.Diseases.DiseasesDetails;
import com.zxc.model.Diseases.Treatment;
import com.zxc.model.Equipment.Equipment;
import com.zxc.model.Fertilizer;
import com.zxc.model.Pesticide;
import com.zxc.model.Plant;
import com.zxc.model.Tools;
import com.zxc.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;


@Service
public class AdminServiceImpl implements AdminService{


        @Autowired
        private AdminDao adminDao;

        //插入植物信息
        @Override
        public int insertPlantInfo(Plant plant) {
            plant.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            int i = adminDao.insertPlantInfo(plant);
            return i;
        }
        //插入病症信息与治疗信息
        @Override
        public int insertDiseasesInfo(DiseasesDetails diseasesDetails) {
            diseasesDetails.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            int i = adminDao.insertDiseasesInfo(diseasesDetails);
            //插入治疗信息
            for(int a = 0;a < diseasesDetails.getTreatmentList().size();a++){
                Treatment treatment = new Treatment();
                //将传入对象里面的list中的对象赋值到新创建的对象中，再进行插入操作
                treatment = diseasesDetails.getTreatmentList().get(a);
                if (treatment.gettType()==1){
                    Pesticide pesticide =new Pesticide();
                    pesticide.setId(treatment.getTypeId());
                    treatment.setTherapeuticDrugs(adminDao.selectPesticideDate(pesticide).get(0).getPesticideName());
                }else {
                    Fertilizer fertilizer =new Fertilizer();
                    fertilizer.setId(treatment.getTypeId());
                    treatment.setTherapeuticDrugs(adminDao.selectFertilizerDate(fertilizer).get(0).getFertilizerName());
                }
                treatment.setTid(UUID.randomUUID().toString().replaceAll("-", ""));
                treatment.setDiseasesId(diseasesDetails.getId());
                adminDao.insertTreatmentInfo(treatment);
            }
            return i;
        }
        //插入设备仓库信息数据
        @Override
        public int insertEquipmentWarehouseData(Equipment equipment) {
            equipment.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            int i = adminDao.insertEquipmentWarehouseData(equipment);
            return i;
        }
        //插入肥料仓库信息数据
        @Override
        public int insertFertilizerWarehouseData(Fertilizer fertilizer) {
            fertilizer.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            int i = adminDao.insertFertilizerWarehouseData(fertilizer);
            return i;
        }
        //插入农药仓库信息数据
        @Override
        public int insertPesticideWarehouseData(Pesticide pesticide) {
            pesticide.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            int i = adminDao.insertPesticideWarehouseData(pesticide);
            return i;
        }
        //插入种子仓库信息数据
        @Override
        public int insertSeedWarehouseData(seeds seeds) {
            seeds.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            int i = adminDao.insertSeedWarehouseData(seeds);
            return i;
        }
        //插入农具仓库信息数据
        @Override
        public int insertToolsWarehouseData(Tools tools) {
            tools.setId(UUID.randomUUID().toString().replaceAll("-", ""));
            int i = adminDao.insertToolsWarehouseData(tools);
            return i;
        }
//修改
//插入肥料仓库信息数据
@Override
public int updateFertilizerWarehouseData(Fertilizer fertilizer) {
    int i = adminDao.updateFertilizerWarehouseData(fertilizer);
    return i;
}
    //插入农药仓库信息数据
    @Override
    public int updatePesticideWarehouseData(Pesticide pesticide) {
        int i = adminDao.updatePesticideWarehouseData(pesticide);
        return i;
    }
    //插入种子仓库信息数据
    @Override
    public int updateSeedWarehouseData(seeds seeds) {
        int i = adminDao.updateSeedWarehouseData(seeds);
        return i;
    }
    //插入农具仓库信息数据
    @Override
    public int updateToolsWarehouseData(Tools tools) {
        int i = adminDao.updateToolsWarehouseData(tools);
        return i;
    }
//    修改
    @Override
    public List<Plant> getPlantDate(Plant plant){
            List<Plant> list =  adminDao.selectPlantDate(plant);
            return list;
}


    //插入肥料信息数据
    @Override
    public int insertFertilizerData(Fertilizer fertilizer) {
        fertilizer.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        int i = adminDao.insertFertilizerData(fertilizer);
        return i;
    }
    //插入农药信息数据
    @Override
    public int insertPesticideData(Pesticide pesticide) {
        pesticide.setId(UUID.randomUUID().toString().replaceAll("-", ""));
        int i = adminDao.insertPesticideData(pesticide);
        return i;
    }





    @Override
    public List<Tools> getToolsDate(Tools tools){
        return adminDao.selectToolsDate(tools);
    }
    @Override
    public List<Pesticide> getPesticideDate(Pesticide pesticide){
        return adminDao.selectPesticideDate(pesticide);
    }
    @Override
    public List<Fertilizer> getFertilizerDate(Fertilizer fertilizer){
        return adminDao.selectFertilizerDate(fertilizer);
    }
    }
